<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <title>EAS - 添加权限节点</title>
    <meta name="keywords" content="OAS,oas,考试,过程,分析,过程分析,结果,面部表情,表情,表情分析,Expression,analysis,表情分析系统,采集,表情趋势,表情变化">
    <meta name="description" content="Expression analysis system(表情分析系统)，用于采集考试过程中学生的表情趋势变化，合理分析考生考试情况。">
    <!--浏览器默认内核指定-->
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <!--指定IE8浏览器去模拟某个特定版本的IE浏览器的渲染方式-->
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <!--设置移动端自适应-->
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <!--禁止搜索引擎转码-->
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <!--在浏览器收藏夹中显示的图标-->
    <link rel="Bookmark" href="/resources/favicon.ico">
    <!--网页标题小图标-->
    <link rel="Shortcut Icon" href="/resources/favicon.ico"/>
    <!--css引入-->
    <link rel="stylesheet" type="text/css" href="/resources/static/h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="/resources/static/h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="/resources/lib/Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="/resources/static/h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="/resources/static/h-ui.admin/css/style.css"/>
    <link rel="stylesheet" type="text/css" href="/resources/lib/zTree_v3/css/zTreeStyle/zTreeStyle.css">
    <style>
        .line{border-top: 0;}
    </style>
    <!--[if lt IE 9]>
    <script type="text/javascript" src="/resources/lib/html5shiv.js"></script>
    <script type="text/javascript" src="/resources/lib/respond.min.js"></script>
    <![endif]-->
    <!--[if IE 6]>
    <script type="text/javascript" src="/resources/lib/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
</head>
<body>
<article class="page-container">
    <form action="" method="post" class="form form-horizontal" id="permissionForm">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>类型：</label>
            <div class="formControls col-xs-8 col-sm-9 skin-minimal">
                <div class="radio-box">
                    <input type="radio" id="type-1" value="0" name="type">
                    <label for="type-1">目录</label>
                </div>
                <div class="radio-box">
                    <input type="radio" id="type-2" value="1" name="type">
                    <label for="type-2">菜单</label>
                </div>
                <div class="radio-box">
                    <input type="radio" id="type-3" value="2" name="type" checked>
                    <label for="type-3">按钮</label>
                </div>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>权限名称：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="权限名称" id="name" autocomplete="off" name="name">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">授权标识：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="授权标识(菜单/按钮需要填写,目录不需要填写)" autocomplete="off" name="url">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-3">
                <span class="c-red">*</span>
                <span id="parentSpan">父节点</span>：
            </label>
            <div class="formControls col-xs-8 col-sm-9">
                <ul class="ztree" id="permissionTree"></ul>
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/resources/lib/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="/resources/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="/resources/static/h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="/resources/static/h-ui.admin/js/H-ui.admin.js"></script>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="/resources/lib/zTree_v3/js/jquery.ztree.all.min.js"></script>
<script type="text/javascript" src="/resources/lib/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="/resources/lib/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="/resources/lib/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
    $(function () {
        // 单选样式
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });

        // zTree设置
        var setting = {
            data: {
                simpleData: {
                    enable: true,
                    idKey: "id",
                    pIdKey: "parentId",
                    rootPId: 0
                }
            },
            check: {
                enable: true,
                chkStyle: "radio",
                radioType: "all"
            }
        };

        // 异步请求所有权限树节点
        var treeObj, loadIndex;
        $.ajax({
            url: '/sys/permission/allNodes',
            type: 'post',
            dataType: 'json',
            data: {roleId: 1},
            beforeSend: function () {
                loadIndex = layer.load(0, {shade: 0.1});
            },
            complete: function () {
                layer.close(loadIndex);
            },
            success: function (data) {
                treeObj = $.fn.zTree.init($("#permissionTree"), setting, data);
                treeObj.expandAll(true);
            },
            error: function () {
                layer.msg('服务器错误', {icon: 5, time: 1000});
            }
        });

        // 添加权限节点
        var loadIndex;
        $("#permissionForm").validate({
            rules: {
                name: {
                    required: true
                }
            },
            onkeyup: false,
            focusCleanup: true,
            success: "valid",
            submitHandler: function (form) {
                var nodes = treeObj.getCheckedNodes(true);
                if (nodes.length != 1) {
                    layer.msg('请选择父节点', {icon: 5, time: 1000});
                    return;
                }
                $(form).ajaxSubmit({
                    url: "/sys/permission/add",
                    type: "post",
                    dataType: "json",
                    data: {parentId: nodes[0].id},
                    beforeSend: function () {
                        loadIndex = layer.load(0, {shade: 0.1});
                    },
                    complete: function () {
                        layer.close(loadIndex);
                    },
                    success: function (data) {
                        if (data.status == 0) {
                            layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                                parent.layer.close(parent.layer.getFrameIndex(window.name));
                            });
                        } else {
                            layer.msg(data.msg, {icon: 5, time: 1000});
                        }
                    },
                    error: function () {
                        layer.msg('服务器错误', {icon: 5, time: 1000});
                    }
                });
            }
        });
    });
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>